import { doGetAppInfo } from '@/api/app'

const state = {
  device: 'desktop',
  theme: 'A',
  info: {}
}

const mutations = {
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  },
  TOGGLE_THEME: (state, theme) => {
    state.theme = theme
  },
  TOGGLE_INFO: (state, info) => {
    for (var k in info) {
      if (object.hasOwnProperty(k)) {
        state.info[k] = info[k]
      }
    }
  },
}

const actions = {
  toggleDevice({ commit }, device) {
    commit('TOGGLE_DEVICE', device)
  },
  toggleDevice({ commit }, theme) {
    commit('TOGGLE_THEME', theme)
  },
  getAppInfo321({ commit, state }) {
    return new Promise((resolve, reject) => {
      doGetAppInfo().then(response => {
        console.log("@/store/app/index.js getAppInfo321()", response)
        const { data } = response
        //
        // if (!data) {
        //   reject('Verification failed, please Login again.')
        // }
        //
        // const { roles, name, avatar, introduction } = data
        //
        // // roles must be a non-empty array
        // if (!roles || roles.length <= 0) {
        //   reject('getInfo: roles must be a non-null array!')
        // }
        //
        commit('TOGGLE_THEME', 'B')
        // commit('SET_ROLES', roles)
        // commit('SET_NAME', name)
        // commit('SET_AVATAR', avatar)
        // commit('SET_INTRODUCTION', introduction)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
